<template>
  <div class="editEenter">
    <TipHead :title="data.title"></TipHead>

    <el-form
      :model="data"
      :rules="rules"
      ref="ruleForm"
      class="title-form"
      label-width="140px"
      label-position="left"> 
      <!-- data.status == 4 等于4，等于上架状态就要不可以编辑 并且 等于-2的时候也要可以编辑 -->
      <el-form-item label="法条标题" prop="title">
        <el-input :disabled="data.status == 4 && modes[0].value != '-2'" v-model="data.title" maxlength="150"></el-input>
      </el-form-item>
      <el-form-item label="法条名称" prop="name">
        <el-input :disabled="data.status == 4 && modes[0].value != '-2'" v-model="data.name" maxlength="150"></el-input>
      </el-form-item>
      <el-form-item label="备注">
        <el-input :disabled="data.status == 4 && modes[0].value != '-2'" v-model="data.history"></el-input>
        <!-- <p class="remark-p">{{data.history}}</p> -->
      </el-form-item>
    </el-form>

    <el-form
      :model="data"
      :rules="rules"
      ref="ruleForm"
      label-width="140px"
      class="demo-ruleForm"
      label-position="left"> 
      <!-- data.status == 4 等于4，等于上架状态就要不可以编辑 并且 等于-2的时候也要可以编辑 -->
      <el-form-item label="适用区域" prop="scope">
        <el-input :disabled="data.status == 4 && modes[0].value != '-2'" v-model="data.scope"></el-input>
      </el-form-item>
      <el-form-item label="效力级别" prop="name">
        <!-- <el-input :disabled="data.status != 0" v-model="data.type"></el-input> -->
        <el-select
          class="test"
          :disabled="data.status == 4 && modes[0].value != '-2'"
          v-model="data.type"
          placeholder="请选择"
        >
          <el-option
            v-for="item in lawSmallOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="发布部门" prop="from">
        <el-input :disabled="data.status == 4 && modes[0].value != '-2'" v-model="data.from"></el-input>
      </el-form-item>

      <el-form-item label="请选择发布时间" prop="publishTime">
        <el-date-picker
          :disabled="data.status == 4 && modes[0].value != '-2'"
          type="date"
          placeholder="选择日期"
          value-format="yyyy-MM-dd"
          v-model="data.publishTime"
          style="width: 100%"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="请选择生效时间" prop="effectiveTime">
        <el-date-picker
          :disabled="data.status == 4 && modes[0].value != '-2'"
          type="date"
          placeholder="选择日期"
          value-format="yyyy-MM-dd"
          v-model="data.effectiveTime"
          style="width: 100%"
        ></el-date-picker>
      </el-form-item>
    </el-form>

    <TipHead title="详细"></TipHead>

    <p
      v-for="item in data.info"
      :key="item.id"
      :class="{ line: true, isChecked: item.isSelect || item.status == 2 }"
      style="margin-bottom: 20px"
      @click="comCheckChange(item)"
    >
      <Comcheck
        v-if="data.status != 4 || modes[0].value == '-2'"
        @change="
          (bln) => {
            selectLaw(bln, item);
          }
        "
        :checked="item.isSelect || item.status == 2"
        :disabled="data.status == 4 && modes[0].value != '-2'"
        style="margin-right: 23px"
      ></Comcheck>
      <span v-html="item.content.join('<br/>')"> </span>
    </p>
    <TipHead title="附件" :isRight="true">
      <label for="upload">
        <div
          style="margin-right: 10px"
          class="el-icon-plus"
          v-if="data.status != 4 || modes[0].value == '-2'"
        ></div>
      </label>
      <input
        multiple
        hidden="true"
        @change="uploadAccessory"
        id="upload"
        type="file"
      />
    </TipHead>
    <div class="accessoryClass" :key="index" v-for="(item, index) in base64Arr">
      <div>附件{{ index + 1 }}</div>

      <a target="_blank" :href="item.url">{{ item.name }}</a>
      <span
        class="el-icon-delete"
        v-if="data.status != 4 || modes[0].value == '-2'"
        @click="deleteAccessory(item)"
      ></span>
    </div>
  </div>
</template>

<script>
import TipHead from "./compoents/tipHead.vue";
import Comcheck from "../../../../components/Comcheck.vue";
import { changeLawType } from "@/wss/utils/wss.js";
export default {
  components: { TipHead, Comcheck },
  props: {
    data: {
      type: Object,
      require: true,
      // 转换type
      // validator(val) {
      //   val.type = changeLawType(val.type);
      //   return true;
      // },
    },
    modes:{
      type: Array
    },
  },
  mounted(files) {
    // this.$nextTick(() => {});
  },
  data() {
    return {
      //
      // 1法律 2宪法 3司法解释 4行政法规 5监察法规 6决定 7地方性法规 8地方规章 9部门规章 10规范性文件 11 行业规范 12行业标准
      lawSmallOptions: [
        {
          value: "1",
          label: "法律",
        },
        {
          value: "2",
          label: "宪法",
        },
        {
          value: "3",
          label: "司法解释",
        },
        {
          value: "4",
          label: "行政法规",
        },
        {
          value: "5",
          label: "监察法规",
        },
        {
          value: "6",
          label: "决定",
        },

        {
          value: "7",
          label: "地方性法规",
        },
        {
          value: "8",
          label: "地方规章",
        },
        {
          value: "9",
          label: "部门规章",
        },
        {
          value: "10",
          label: "规范性文件",
        },
        {
          value: "11",
          label: "行业规范",
        },
        {
          value: "12",
          label: "行业标准",
        },
      ],
      base64Arr: [],
      checked: "",
      isChecked: false,
      // 当前标题
      title: "",

      rules: {
        title: [{ required: true, message: "请输入法律标题", trigger: "blur" }],
        name: [{ required: true, message: "请输入法律名称", trigger: "blur" }],
        scope: [{ required: true, message: "请输入范围", trigger: "blur" }],
        from: [{ required: true, message: "请输入来源", trigger: "blur" }],
        publishTime: [
          {
            type: "date",
            required: true,
            message: "请选择发布日期",
            trigger: "change",
          },
        ],
        effectiveTime: [
          {
            type: "date",
            required: true,
            message: "请选择生效时间",
            trigger: "change",
          },
        ],
      },
    };
  },
  watch: {
    // data: {
    //   handler(Object) {
    //     console.log(Object);
    //     this.base64Arr = Object.files;
    //   },
    //   deep: true,
    // },
  },
  filters: {
    filterContent(data) {
      return data.join("<br/>");
    },
  },

  methods: {
    setDomStyle() {
      setTimeout(() => {
        console.log(document.querySelector(".v-modal"));
        if (document.querySelector(".v-modal")) {
          document.querySelector(".v-modal").style.zIndex = "1500";
        }
      }, 0);
    },
    // 是否禁用法律
    selectLaw(bln, item) {
      bln ? (item.status = 2) : (item.status = 1);
    },
    // 转换成base64
    getBase64Fn() {
      return this.base64Arr;
    },
    // 删除附件
    deleteAccessory(file) {
      this.base64Arr = this.base64Arr.filter((item) => {
        return item.id != file.id;
      });
    },
    // 转换成base64
    changeto64(file) {
      let reader = new FileReader();
      reader.addEventListener(
        "load",
        () => {
          this.base64Arr.push({
            base64: reader.result.split(",")[1],
            name: file.name,
            url: reader.result.split(",")[1],
            // url: URL.createObjectURL(file),
            id: file.lastModified,
          });
        },
        false
      );

      if (file) {
        reader.readAsDataURL(file);
        console.log(this.base64Arr);
      }
    },
    // 上传附件触发
    uploadAccessory({ target }) {
      let files = target.files;
      for (let index = 0; index < files.length; index++) {
        this.changeto64(files[index]);
      }
    },

    // 选择框改变时
    comCheckChange(item) {
      if (this.data.status != 0) {
        return;
      }
      this.$set(item, "isSelect", !item.isSelect);
    },
  },
};
</script>

<style lang="scss" scoped>
.editEenter {
  .accessoryClass {
    margin-right: 10px;
    display: flex;

    justify-content: space-between;

    margin-bottom: 10px;
    height: 60px;
    align-items: center;
    a {
      display: block;
      margin: 0px 11px;

      border-bottom: 1px solid #ededed;
      flex: 1;
    }
    > * {
      height: 70%;
    }
  }
  ::v-deep .title-form .el-form-item{
    margin-bottom: 20px;
  }
  ::v-deep .demo-ruleForm {
    width: 100%;
    display: grid;
    grid-row-gap: 20px;
    grid-template-columns: 1fr 1fr;
    margin-bottom: 20px;
  }
  .el-form-item {
    margin-top: 0px;
  }
  .line {
    // justify-content: space-between;
    display: flex;
    align-items: center;
    font-size: 14px;
  }
  .isChecked {
    color: #e9ebec;
  }
}
::v-deep .el-select {
  width: 100%;
}

::v-deep .el-select-dropdown.el-popper {
  z-index: 2070 !important;
}
::v-deep .demo-ruleForm .el-form-item:nth-child(2n) .el-form-item__label {
  padding-left: 20px;
}
::v-deep .el-icon-delete {
  cursor: pointer;
}

.remark-p{
  margin: 0;
  color: #666;
  line-height: 26px;
}
</style>